// components/pick/index.js
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
  },
  properties: {
    info: {
      type: Object
    }
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    ready() {},
    attached: function () {},
    moved: function () {},
    detached: function () {},
  },

  /**
   * 组件的初始数据
   */
  data: {
    selected: '../../icon/checked.png',
    unselected: '../../icon/check.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 选中
    handleChecked(e) {
      const result = []
      const idx = e.currentTarget.dataset.index
      const info = this.data.info.list
      const type_name = this.data.info.type_name
      const type_id = this.data.info.type_id
      info.map((item, index) => {
        item.checked = idx === index ? !item.checked : item.checked
        result.push(item)
      })
      this.setData({
        info: Object.assign({}, {
          type_name,
          list: result,
          type_id
        })
      })
      this.triggerEvent('select', this.data.info)
    }
  }
})